package scr.springbootcaffeineredis;

import com.github.benmanes.caffeine.cache.Cache;
import io.lettuce.core.support.caching.CacheAccessor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CaffeineCacheAccessor implements CacheAccessor {
    private Cache cache;

    public CaffeineCacheAccessor(Cache cache) {
        this.cache = cache;
    }

    @Override
    public Object get(Object key) {
        log.info("Caffeine get => {}", key);
        return cache.getIfPresent(key);
    }

    @Override
    public void put(Object key, Object value) {
        log.info("Caffeine put => {} : {}", key, value);
        cache.put(key, value);
    }

    @Override
    public void evict(Object key) {
        log.info("Caffeine evict => {}", key);
        cache.invalidate(key);
    }
}
